﻿
CREATE  FUNCTION [DateToString] (@date as datetime)  
RETURNS varchar(10) AS  
BEGIN 
	if (@date IS NULL)
		return ''

	declare @day as varchar(2)
	declare @month as varchar(2)
	declare @year as varchar(4)
	declare @result as varchar(10)
	set @result = '';
	set @day = '';
	set @month = '';
	set @year = '';
	if  day(@date) > 9
		set @day = cast( day(@date) as varchar(2));
	else
		set @day = '0' + cast( day(@date) as varchar(1));
	if  month(@date) > 9
		set @month = cast( month(@date) as varchar(2));
	else
		set @month = '0' + cast( month(@date) as varchar(1));
	set @year = cast( year(@date) as varchar(4));
	set @result = @day + '/' + @month + '/' +@year;
	return @result;
END